package com.plugin.seed.mybatis.defaultvalue.configuration;

import com.plugin.seed.mybatis.defaultvalue.interceptor.ColumnDefaultValueQueryInterceptor;
import com.plugin.seed.mybatis.defaultvalue.interceptor.ColumnDefaultValueUpdateInterceptor;
import com.plugin.seed.mybatis.defaultvalue.processor.SeedMybatisBeanPostProcessor;
import com.plugin.seed.mybatis.defaultvalue.type.BooleanDefaultValueTypeHandler;
import com.plugin.seed.mybatis.defaultvalue.type.StringDefaultValueTypeHandler;
import com.plugin.seed.mybatis.defaultvalue.typeenum.EnumOrdinalDefaultValueTypeHandler;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Peter Fan
 */
@Configuration
public class SeedMybatisPluginConfiguration {

    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return configuration -> {
            configuration.setCacheEnabled(false);
            configuration.setDefaultStatementTimeout(5);
            configuration.setMapUnderscoreToCamelCase(true);
            configuration.setUseGeneratedKeys(true);
            configuration.setDefaultEnumTypeHandler(EnumOrdinalDefaultValueTypeHandler.class);
        };
    }

    @Bean
    public StringDefaultValueTypeHandler stringDefaultValueTypeHandler() {
        return new StringDefaultValueTypeHandler();
    }

    @Bean
    public BooleanDefaultValueTypeHandler booleanDefaultValueTypeHandler() {
        return new BooleanDefaultValueTypeHandler();
    }

    @Bean
    public SeedMybatisBeanPostProcessor seedMybatisBeanPostProcessor() {
        return new SeedMybatisBeanPostProcessor();
    }

    @Bean
    public ColumnDefaultValueUpdateInterceptor columnDefaultValueUpdateInterceptor() {
        return new ColumnDefaultValueUpdateInterceptor();
    }

    @Bean
    public ColumnDefaultValueQueryInterceptor columnDefaultValueQueryInterceptor() {
        return new ColumnDefaultValueQueryInterceptor();
    }




}
